package com.commons.base.model;

import java.io.Serializable;

/**
 * 返回实体类
 * 
 * @author xkq
 * @date 2018年8月3日
 */

public class ResultData<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	public ResultData() {
	};

	private ResultData(Builder<T> builder) {
		this.code = builder.getCode();
		this.message = builder.getMessage();
		this.data = builder.getData();
		this.isOk = (this.code == ResultCode.success.getCode());
	};

	private Boolean isOk = true;
	private String code = ResultCode.success.getCode();
	private String message = ResultCode.success.getMessage();
	private T data;

	/**
	 * isOk
	 *
	 * @return the isOk
	 */

	public Boolean getIsOk() {
		return isOk;
	}

	/**
	 * @param isOk the isOk to set
	 */

	public void setIsOk(Boolean isOk) {
		this.isOk = isOk;
	}

	/**
	 * code
	 *
	 * @return the code
	 */

	public String getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */

	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * msg
	 *
	 * @return the msg
	 */

	public String getMessage() {
		return message;
	}

	/**
	 * @param message the msg to set
	 */

	public void setMessage(String message) {
		this.message = message;
	}

	/**
	 * data
	 *
	 * @return the data
	 */

	public T getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */

	public ResultData<T> setData(T data) {
		this.data = data;
		return this;
	}

	public static class Builder<T> {
		// 必要参数
		private final String code;
		private String message;
		private T data;
		// 可选参数

		public Builder(ResultCode resultCode) {
			this.code = resultCode.getCode();
			this.message = resultCode.getMessage();
		}
//		public Builder() {
//			this.code = ResultCode.success.getCode();
//			this.msg = ResultCode.success.getMsg();
//		}

		/**
		 * data
		 *
		 * @return the data
		 */

		public T getData() {
			return data;
		}

		/**
		 * @param data the data to set
		 */

		public Builder<T> setData(T data) {
			this.data = data;
			return this;
		}

		/**
		 * code
		 *
		 * @return the code
		 */

		public String getCode() {
			return code;
		}

		/**
		 * msg
		 *
		 * @return the msg
		 */

		public String getMessage() {
			return message;
		}

		/**
		 * @param message the msg to set
		 */

		public Builder<T> setMessage(String message) {
			this.message = message;
			return this;
		}

		public ResultData<T> build() {
			return new ResultData<T>(this);
		}
	}

}
